<template>
	<el-form label-width="130px" :model="form" :rules="rules" ref="queryForm">
		<el-row>
			<el-col :span="24">
				<el-form-item label="指挥席位名称" prop="name">
					<el-input v-model="form.name" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="职务" prop="zwName">
					<el-input v-model="form.zwName" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="负责人姓名" prop="principal">
					<el-input v-model="form.principal" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="联系方式" prop="phonea">
					<el-input v-model="form.phonea" style="width: 190px;"
					@input="e => regOnlyNumSpot(e, form, 'phonea', 0)"></el-input>
				</el-form-item>
			</el-col>
		</el-row>
		<div style="display: flex;justify-content: flex-end;">
			<el-button @click="closethis()" @keyup.prevent @keydown.enter.prevent>取消</el-button>
			<el-button type="primary" @click="submit(queryForm)" @keyup.prevent @keydown.enter.prevent>确定</el-button>
		</div>
	</el-form>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted
	} from 'vue'
	import {
		ElMessage
	} from 'element-plus'

	import {
		commonInterface
	} from '@/api/common/common'
	
	import {
		regOnlyNumSpot
	} from '@/utils/reg'



	const emit = defineEmits(['getList', 'closeWindow'])
	const props = defineProps(['editData','unit'])
	const form = ref({
		unit:null,
	})
	const queryForm = ref('')


	//必填项
	const rules = reactive({

	})
	//取消
	const closethis = () => {
		emit('closeWindow')
	}

	//确定
	const submit = async (e) => {
		if (!e) return
		await e.validate((valid) => {
			if (valid) {
				let method = 'post'
				if (props.editData) method = 'put'
				commonInterface('/back/renfang/jjmb/party/', form.value, method).then(result => {
					if (result.code === 200) {
						ElMessage.success(result.msg)
						emit('closeWindow')
						emit('getList')
					} else {
						ElMessage.error(result.msg)
					}
				})
			}
		})
	}

	onMounted(() => {
		form.value.unit = props.unit
		if (props.editData) form.value = props.editData
	})
</script>

<style>
</style>